<?php

/**
 * Created by PhpStorm.
 * User: steven
 * Date: 2016/4/20
 * Time: 19:31
 */
class Category_Model extends CI_Model
{
    public function __construct()
    {
        $this->load->database();
    }

//    查询类目列表
    public function get_category_list($data){
        $sql="select * from category where is_deleted='N'";
        if(isset($data['category_name'])){
            $sql=$sql." and category_name='".$data['category_name']."'";
        }
        if(isset($data['sort'])){
            $sql=$sql." order by ".$data['sort'];
        }
        if(isset($data['start_row'])){
            $sql=$sql." limit ".$data['start_row'].",".$data['number'];
        }
        $query=$this->db->query($sql);
        return $query->result_array();
    }

//    根据id查询类目
    public function get_category_by_id($id){
        $query=$this->db->where('id',$id);
        return $query->row();
    }

//    新增类目
    public function add_category($data){
        $query=$this->db->insert('category',$data);
        $affectioned=$this->db->affected_rows();
        if($affectioned==1){
            return true;
        }else{
            return false;
        }
    }

//    删除文章
    public function delete_category_by_id($id){
        $this->db->set('is_deleted', 'Y');
        $this->db->set('gmt_modify', date("Y-m-d H:i:s" ,time()));
        $this->db->where('id', $id);
        $this->db->update('category');
        $affectioned=$this->db->affected_rows();
        if($affectioned>0){
            return true;
        }else{
            return false;
        }
    }
}